package com.scuvc.utils;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class ImageUtils {
    public static ImageIcon createAlphaIcon(ImageIcon icon, float alpha,int w,int h) {
        //创建一个 Graphics2D对象，可以将它绘制到BufferedImage中
        BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = bimage.createGraphics();
        //为 Graphics2D 上下文设置，创建一个具有指定规则的AlphaComposite对象
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        //绘制图标
        icon.paintIcon(null, g2, 0, 0);
        //释放此图形的所有系统资源
        g2.dispose();
        return new ImageIcon(bimage);
    }
}
